Repository: DiceDB/dice
File: integration_tests/commands/resp/getwatch_test.go (Go)

Code before:
			assert.Nil(t, err)
			castedValue, ok := v.([]interface{})
			if !ok {
				t.Errorf("Type assertion to []interface{} failed for value: %v", v)
			}
			assert.Equal(t, 3, len(castedValue))
			assert.Equal(t, "GET", castedValue[0])
			assert.Equal(t, "2714318480", castedValue[1])
			assert.Equal(t, tc.val, castedValue[2])
		}
	}
}

func TestGETWATCHWithSDK(t *testing.T) {
	publisher := getLocalSdk()
	subscribers := []WatchSubscriber{{client: getLocalSdk()}, {client: getLocalSdk()}, {client: getLocalSdk()}}

	publisher.Del(context.Background(), getWatchKey)

	channels := make([]<-chan *dicedb.WatchResult, len(subscribers))
	for i, subscriber := range subscribers {
		watch := subscriber.client.WatchConn(context.Background())
		subscribers[i].watch = watch
		assert.True(t, watch != nil)

		uuid := uuid.New().String()
		firstMsg, err := watch.Watch(context.Background(), "GET", getWatchKey, uuid)
		assert.Nil(t, err)
		assert.Equal(t, uuid, firstMsg.Command)
		assert.Equal(t, "2714318480", firstMsg.Fingerprint)

		channels[i] = watch.Channel()
	}

	for _, tc := range getWatchTestCases {
		err := publisher.Set(context.Background(), tc.key, tc.val, 0).Err()
		assert.Nil(t, err)

		for _, channel := range channels {
			v := <-channel
			assert.Equal(t, "GET", v.Command)            // command
			assert.Equal(t, "2714318480", v.Fingerprint) // Fingerprint
			assert.Equal(t, tc.val, v.Data.(string))     // data
		}
	}
}

func TestGETWATCHWithSDK2(t *testing.T) {
	publisher := getLocalSdk()
	subscribers := []WatchSubscriber{{client: getLocalSdk()}, {client: getLocalSdk()}, {client: getLocalSdk()}}


Review comment (suggestion):
I don't think we need to send the uuid on the user side, the SDK already creates one for us inside the Watch() method.
```suggestion
```

Code after:
	unsubscribeFromUpdates(t, subscribers, "2714318480")
}

func TestGETWATCHWithSDK(t *testing.T) {
	publisher := getLocalSdk()
	subscribers := []WatchSubscriber{{client: getLocalSdk()}, {client: getLocalSdk()}, {client: getLocalSdk()}}

	defer func() {
		err := ClosePublisherSubscribersSDK(publisher, subscribers)
		assert.Nil(t, err)
	}()

	publisher.Del(context.Background(), getWatchKey)

	channels := make([]<-chan *dicedb.WatchResult, len(subscribers))
	for i, subscriber := range subscribers {
		// subscribe to updates
		watch := subscriber.client.WatchConn(context.Background())
		subscribers[i].watch = watch
		assert.True(t, watch != nil)

		firstMsg, err := watch.Watch(context.Background(), "GET", getWatchKey)
		assert.Nil(t, err)
		assert.Equal(t, "2714318480", firstMsg.Fingerprint)

		channels[i] = watch.Channel()
	}

	for _, tc := range getWatchTestCases {
		err := publisher.Set(context.Background(), tc.key, tc.val, 0).Err()
		assert.Nil(t, err)

		for _, channel := range channels {
			v := <-channel
			assert.Equal(t, "GET", v.Command)            // command
			assert.Equal(t, "2714318480", v.Fingerprint) // Fingerprint
			assert.Equal(t, tc.val, v.Data.(string))     // data
		}
	}

	// unsubscribe from updates
	unsubscribeFromUpdatesSDK(t, subscribers, "2714318480")
}

func TestGETWATCHWithSDK2(t *testing.T) {
	publisher := getLocalSdk()
	subscribers := []WatchSubscriber{{client: getLocalSdk()}, {client: getLocalSdk()}, {client: getLocalSdk()}}

	defer func() {
		err := ClosePublisherSubscribersSDK(publisher, subscribers)
		assert.Nil(t, err)