Skip to content

Commit

Permalink
Merge pull request #16 from brotherlogic/fix_double_push
Browse files Browse the repository at this point in the history
Added failing test of matching intents
  • Loading branch information
brotherlogic authored May 11, 2017
2 parents e1a6b57 + ad9153e commit 5b3dd89
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
26 changes: 25 additions & 1 deletion master.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,31 @@ func getFleetStatus(c checker) map[string]*pbs.JobList {
}

func configDiff(cm, cs *pb.Config) *pb.Config {
return cm
retConfig := &pb.Config{}

log.Printf("COMPARE %v to %v", cm, cs)
for _, entry := range cm.Intents {
nIntent := &pb.Intent{}
nIntent.Spec = entry.Spec
nIntent.Masters = entry.Masters
nIntent.Slaves = entry.Slaves
retConfig.Intents = append(retConfig.Intents, nIntent)
}

log.Printf("FIRST PASS: %v", retConfig)
for _, entry := range cs.Intents {
for _, pair := range retConfig.Intents {
if entry.Spec.Name == pair.Spec.Name {
log.Printf("FOUND: %v", pair)
pair.Masters -= entry.Masters
pair.Slaves -= entry.Slaves
log.Printf("RESULT: %v", retConfig)
}
}
}

log.Printf("RETURNING: %v", retConfig)
return retConfig
}

func loadConfig(f string) (*pb.Config, error) {
Expand Down
11 changes: 11 additions & 0 deletions master_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ func TestDiff(t *testing.T) {
}
}

func TestDiffWhenMatch(t *testing.T) {
i1 := &pb.Intent{Spec: &pbs.JobSpec{Name: "testing"}, Masters: 1}
c1 := &pb.Config{Intents: []*pb.Intent{i1}}
c2 := &pb.Config{Intents: []*pb.Intent{i1}}

diff := configDiff(c1, c2)
if len(diff.Intents) != 0 && diff.Intents[0].Masters != 0 {
t.Errorf("Error in diff: %v", diff)
}
}

func TestClean(t *testing.T) {
blank()
}

0 comments on commit 5b3dd89

Please sign in to comment.