mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-20 18:31:15 +00:00
kubeadm: unittest might run as non-root
Signed-off-by: Dave Chen <dave.chen@arm.com>
This commit is contained in:
parent
575616cc72
commit
49732716de
@ -77,6 +77,7 @@ func TestEnforceRequirements(t *testing.T) {
|
|||||||
dryRun bool
|
dryRun bool
|
||||||
flags applyPlanFlags
|
flags applyPlanFlags
|
||||||
expectedErr string
|
expectedErr string
|
||||||
|
expectedErrNonRoot string
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Fail pre-flight check",
|
name: "Fail pre-flight check",
|
||||||
@ -84,6 +85,7 @@ func TestEnforceRequirements(t *testing.T) {
|
|||||||
kubeConfigPath: fullPath,
|
kubeConfigPath: fullPath,
|
||||||
},
|
},
|
||||||
expectedErr: "ERROR CoreDNSUnsupportedPlugins",
|
expectedErr: "ERROR CoreDNSUnsupportedPlugins",
|
||||||
|
expectedErrNonRoot: "user is not running as", // user is not running as (root || administrator)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Bogus preflight check specify all with individual check",
|
name: "Bogus preflight check specify all with individual check",
|
||||||
@ -109,8 +111,13 @@ func TestEnforceRequirements(t *testing.T) {
|
|||||||
t.Error("Expected error, but got success")
|
t.Error("Expected error, but got success")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil && !strings.Contains(err.Error(), tt.expectedErr) {
|
expErr := tt.expectedErr
|
||||||
t.Fatalf("enforceRequirements returned unexpected error, expected: %s, got %v", tt.expectedErr, err)
|
// pre-flight check expects the user to be root, so the root and non-root should hit different errors
|
||||||
|
if os.Getuid() != 0 && len(tt.expectedErrNonRoot) != 0 {
|
||||||
|
expErr = tt.expectedErrNonRoot
|
||||||
|
}
|
||||||
|
if err != nil && !strings.Contains(err.Error(), expErr) {
|
||||||
|
t.Fatalf("enforceRequirements returned unexpected error, expected: %s, got %v", expErr, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user