func checkMinionEquals(t *testing.T, conn db.Conn, exp db.Minion) { timeout := time.After(1 * time.Second) var actual db.Minion for { actual, _ = conn.MinionSelf() actual.ID = 0 if reflect.DeepEqual(exp, actual) { return } select { case <-timeout: t.Errorf("Expected minion to be %v, but got %v\n", exp, actual) return default: time.Sleep(100 * time.Millisecond) } } }
func TestSetMinionConfig(t *testing.T) { t.Parallel() s := server{db.New()} cfg := pb.MinionConfig{ Role: pb.MinionConfig_MASTER, PrivateIP: "priv", Spec: "spec", Provider: "provider", Size: "size", Region: "region", EtcdMembers: []string{"etcd1", "etcd2"}, AuthorizedKeys: []string{"key1", "key2"}, } expMinion := db.Minion{ Self: true, Spec: "spec", Role: db.Master, PrivateIP: "priv", Provider: "provider", Size: "size", Region: "region", AuthorizedKeys: "key1\nkey2", } _, err := s.SetMinionConfig(nil, &cfg) assert.NoError(t, err) checkMinionEquals(t, s.Conn, expMinion) checkEtcdEquals(t, s.Conn, db.Etcd{ EtcdIPs: []string{"etcd1", "etcd2"}, }) // Update a field. cfg.Spec = "new" expMinion.Spec = "new" cfg.EtcdMembers = []string{"etcd3"} _, err = s.SetMinionConfig(nil, &cfg) assert.NoError(t, err) checkMinionEquals(t, s.Conn, expMinion) checkEtcdEquals(t, s.Conn, db.Etcd{ EtcdIPs: []string{"etcd3"}, }) }