This repository has been archived by the owner on Mar 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Lantao Liu <lantaol@google.com>
- Loading branch information
1 parent
ebb0928
commit 3b49d3f
Showing
15 changed files
with
495 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
Copyright 2019 The containerd Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package server | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/assert" | ||
|
||
containerstore "github.com/containerd/cri/pkg/store/container" | ||
) | ||
|
||
// TestSetContainerStarting tests setContainerStarting sets removing | ||
// state correctly. | ||
func TestSetContainerStarting(t *testing.T) { | ||
testID := "test-id" | ||
for desc, test := range map[string]struct { | ||
status containerstore.Status | ||
expectErr bool | ||
}{ | ||
|
||
"should not return error when container is in created state": { | ||
status: containerstore.Status{ | ||
CreatedAt: time.Now().UnixNano(), | ||
}, | ||
expectErr: false, | ||
}, | ||
"should return error when container is in running state": { | ||
status: containerstore.Status{ | ||
CreatedAt: time.Now().UnixNano(), | ||
StartedAt: time.Now().UnixNano(), | ||
}, | ||
expectErr: true, | ||
}, | ||
"should return error when container is in exited state": { | ||
status: containerstore.Status{ | ||
CreatedAt: time.Now().UnixNano(), | ||
StartedAt: time.Now().UnixNano(), | ||
FinishedAt: time.Now().UnixNano(), | ||
}, | ||
expectErr: true, | ||
}, | ||
"should return error when container is in unknown state": { | ||
status: containerstore.Status{ | ||
CreatedAt: 0, | ||
StartedAt: 0, | ||
FinishedAt: 0, | ||
}, | ||
expectErr: true, | ||
}, | ||
"should return error when container is in starting state": { | ||
status: containerstore.Status{ | ||
CreatedAt: time.Now().UnixNano(), | ||
Starting: true, | ||
}, | ||
expectErr: true, | ||
}, | ||
"should return error when container is in removing state": { | ||
status: containerstore.Status{ | ||
CreatedAt: time.Now().UnixNano(), | ||
Removing: true, | ||
}, | ||
expectErr: true, | ||
}, | ||
} { | ||
t.Logf("TestCase %q", desc) | ||
container, err := containerstore.NewContainer( | ||
containerstore.Metadata{ID: testID}, | ||
containerstore.WithFakeStatus(test.status), | ||
) | ||
assert.NoError(t, err) | ||
err = setContainerStarting(container) | ||
if test.expectErr { | ||
assert.Error(t, err) | ||
assert.Equal(t, test.status, container.Status.Get(), "metadata should not be updated") | ||
} else { | ||
assert.NoError(t, err) | ||
assert.True(t, container.Status.Get().Starting, "starting should be set") | ||
assert.NoError(t, resetContainerStarting(container)) | ||
assert.False(t, container.Status.Get().Starting, "starting should be reset") | ||
} | ||
} | ||
} |
Oops, something went wrong.