// Copyright 2021 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.

// This file only contains version related variables and consts, all
// type definitions and functions shall not be implemented here.
// This file is excluded from CI tests.

package configuration

import (
	"strings"
	"testing"

	"github.com/onsi/gomega"
)

//func TestSplitHostPath(t *testing.T) {
//	g := gomega.NewWithT(t)
//
//	tests := map[string][]string{
//		"172.16.5.1/a/b/c/d":   {"172.16.5.1", "/a/b/c/d"},
//		"172.16.5.2":           {"172.16.5.2", "/"},
//		"172.16.5.2/test.conf": {"172.16.5.2", "/test.conf"},
//	}
//
//	for p, xs := range tests {
//		host, path := splitHostPath(p)
//		g.Expect(host).To(gomega.Equal(xs[0]))
//		g.Expect(path).To(gomega.Equal(xs[1]))
//	}
//}

func TestConfigurationIterator(t *testing.T) {
	g := gomega.NewWithT(t)

	iter := NewConfigurationIterator(
		strings.NewReader("configuration-content"),
		"172.16.5.2/test.conf",
		"uuid-of-package",
		"instance",
		"172.16.5.2",
		"system",
	)

	rec, hasNext := iter.Next()
	g.Expect(hasNext).To(gomega.BeTrue())
	r, ok := rec.(ConfigurationRecord)
	g.Expect(ok).To(gomega.BeTrue())
	g.Expect(r.PackageID).To(gomega.Equal("uuid-of-package"))
	g.Expect(r.Host).To(gomega.Equal("172.16.5.2"))
	g.Expect(r.Path).To(gomega.Equal("172.16.5.2/test.conf"))
	g.Expect(r.Content).To(gomega.Equal("configuration-content"))

	rec, hasNext = iter.Next()
	g.Expect(hasNext).To(gomega.BeFalse())
	r, ok = rec.(ConfigurationRecord)
	g.Expect(ok).To(gomega.BeTrue())
	g.Expect(r.PackageID).To(gomega.Equal(""))
	g.Expect(r.Host).To(gomega.Equal(""))
	g.Expect(r.Path).To(gomega.Equal(""))
	g.Expect(r.Content).To(gomega.Equal(""))
}
