base_test.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // Copyright 2019 Yunion
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package fsdriver
  15. import (
  16. "testing"
  17. deployapi "yunion.io/x/onecloud/pkg/hostman/hostdeployer/apis"
  18. )
  19. func TestMergeAuthorizedKeys(t *testing.T) {
  20. type args struct {
  21. oldKeys string
  22. pubkeys *deployapi.SSHKeys
  23. }
  24. tests := []struct {
  25. name string
  26. args args
  27. admin bool
  28. want string
  29. }{
  30. {
  31. name: "MergeAuthorizedKeys",
  32. args: args{
  33. oldKeys: "ssh-rsa KEY",
  34. pubkeys: &deployapi.SSHKeys{},
  35. },
  36. admin: true,
  37. want: "ssh-rsa KEY\n",
  38. },
  39. {
  40. name: "MergeAuthorizedKeys",
  41. args: args{
  42. oldKeys: "ssh-rsa KEY " + sshKeySignature,
  43. pubkeys: &deployapi.SSHKeys{},
  44. },
  45. admin: true,
  46. want: "\n",
  47. },
  48. }
  49. for _, tt := range tests {
  50. t.Run(tt.name, func(t *testing.T) {
  51. if got := MergeAuthorizedKeys(tt.args.oldKeys, tt.args.pubkeys, tt.admin); got != tt.want {
  52. t.Errorf("MergeAuthorizedKeys() = %v, want %v", got, tt.want)
  53. }
  54. })
  55. }
  56. }