package main import ( "testing" "github.com/stretchr/testify/require" ) func TestRemove(t *testing.T) { require := require.New(t) s := []*sshKey{ {algorithm: "ssh-ed25519", pubKey: "sdfsdf", alias: "hello@world"}, {algorithm: "ssh-rsa", pubKey: "asdfasdadsad", alias: "world@hello"}, } r := []*sshKey{ {algorithm: "ssh-ed25519", pubKey: "sdfsdf", alias: "hello@world"}, } result := removeSSHKeys(s, r) require.Len(result, 1) r = []*sshKey{ {algorithm: "ssh-ed25519", pubKey: "sdfsdf", alias: "hello@world"}, {algorithm: "ssh-rsa", pubKey: "asdfasdadsad", alias: "world@hello"}, } result = removeSSHKeys(s, r) require.Len(result, 0) r = []*sshKey{ {algorithm: "ssh-ed25519", pubKey: "sdfsdf"}, } result = removeSSHKeys(s, r) require.Len(result, 1) } func TestSSHKeyString(t *testing.T) { require := require.New(t) s := []*sshKey{ {algorithm: "ssh-ed25519", pubKey: "sdfsdf", alias: "hello@world"}, {algorithm: "ssh-rsa", pubKey: "asdfasdadsad", alias: "world@hello"}, {algorithm: "ssh-rsa", pubKey: "asdfasdsdfsfadsad"}, } b := []string{ "ssh-ed25519 sdfsdf hello@world", "ssh-rsa asdfasdadsad world@hello", "ssh-rsa asdfasdsdfsfadsad", } for i := range s { require.Equal(b[i], s[i].String()) } }