log_test.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Copyright 2015 CoreOS, Inc.
  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 migrate
  15. import (
  16. "fmt"
  17. "net/url"
  18. "reflect"
  19. "testing"
  20. "time"
  21. )
  22. func TestNewCommand(t *testing.T) {
  23. entries, err := DecodeLog4FromFile("fixtures/cmdlog")
  24. if err != nil {
  25. t.Errorf("read log file error: %v", err)
  26. }
  27. zeroTime, err := time.Parse(time.RFC3339, "1969-12-31T16:00:00-08:00")
  28. if err != nil {
  29. t.Errorf("couldn't create time: %v", err)
  30. }
  31. m := NewMember("alice", []url.URL{{Scheme: "http", Host: "127.0.0.1:7001"}}, etcdDefaultClusterName)
  32. m.ClientURLs = []string{"http://127.0.0.1:4001"}
  33. tests := []interface{}{
  34. &JoinCommand{"alice", "http://127.0.0.1:7001", "http://127.0.0.1:4001", *m},
  35. &NOPCommand{},
  36. &NOPCommand{},
  37. &RemoveCommand{"alice", 0xe52ada62956ff923},
  38. &CompareAndDeleteCommand{"foo", "baz", 9},
  39. &CompareAndSwapCommand{"foo", "bar", zeroTime, "baz", 9},
  40. &CreateCommand{"foo", "bar", zeroTime, true, true},
  41. &DeleteCommand{"foo", true, true},
  42. &SetCommand{"foo", "bar", zeroTime, true},
  43. &SyncCommand{zeroTime},
  44. &UpdateCommand{"foo", "bar", zeroTime},
  45. }
  46. raftMap := make(map[string]uint64)
  47. for i, test := range tests {
  48. e := entries[i]
  49. cmd, err := NewCommand4(e.GetCommandName(), e.GetCommand(), raftMap)
  50. if err != nil {
  51. t.Errorf("#%d: %v", i, err)
  52. continue
  53. }
  54. if !reflect.DeepEqual(cmd, test) {
  55. if i == 5 {
  56. fmt.Println(cmd.(*CompareAndSwapCommand).ExpireTime.Location())
  57. }
  58. t.Errorf("#%d: cmd = %+v, want %+v", i, cmd, test)
  59. }
  60. }
  61. }