コード例 #1
0
ファイル: example1_table_test.go プロジェクト: nitsnwits/go
// TestTableStation checks the station service call is working
func TestTableStation(t *testing.T) {
	// Iterate through the slice of station ids.
	for index := 0; index < len(stationIDs); index++ {
		// Station id to test.
		stationID := stationIDs[index]

		// Perform call to find a station.
		station, err := buoy.FindStation(stationID)

		// We should not get an error.
		t.Log("There should be no error after the call to FindStation.")
		if err != nil {
			t.Fatalf("ERROR : %s", err)
		}

		// We should not have a nil pointer for the station.
		t.Log("We should not have a nil pointer for the station.")
		if station == nil {
			t.Fatalf("ERROR : %s", err)
		}

		// We should get back the station document.
		t.Logf("StationID \"%s\" should match \"%s\" in the station document.", stationID, station.StationID)
		if station.StationID != stationID {
			t.Errorf("ERROR : Expecting[%s] Received[%s]", stationID, station.StationID)
		}
	}
}
コード例 #2
0
ファイル: example1_test.go プロジェクト: nitsnwits/go
// TestStation checks the station service call is working
func TestStation(t *testing.T) {
	// Perform call to find a station.
	stationID := "42002"
	station, err := buoy.FindStation(stationID)

	// We should not get an error.
	t.Log("There should be no error after the call to FindStation.")
	if err != nil {
		t.Fatalf("ERROR : %s", err)
	}

	// We should not have a nil pointer for the station.
	t.Log("We should not have a nil pointer for the station.")
	if station == nil {
		t.Fatalf("ERROR : %s", err)
	}

	// We should get back the station document.
	t.Logf("StationID \"%s\" should match \"%s\" in the station document.", stationID, station.StationID)
	if station.StationID != stationID {
		t.Errorf("ERROR : Expecting[%s] Received[%s]", stationID, station.StationID)
	}

	// The name in this document should match this known value.
	name := "Station 42002 - West Gulf"
	t.Logf("Name \"%s\" should match \"%s\" in the station document.", name, station.Name)
	if station.Name != name {
		t.Errorf("ERROR : Expecting[%s] Received[%s]", name, station.Name)
	}
}
コード例 #3
0
ファイル: example1_test.go プロジェクト: nitsnwits/go
// Test_InvalidStation checks that an error occurs with an invalid station id.
func Test_InvalidStation(t *testing.T) {
	// Perform call to find a station.
	stationID := "00000"
	station, err := buoy.FindStation(stationID)

	// We should not get an error.
	t.Log("There should be no error after the call to FindStation.")
	if err != nil {
		t.Fatalf("ERROR : %s", err)
	}

	// We should have a nil pointer for the station.
	t.Log("We should get back a nil pointer for the station.")
	if station != nil {
		t.Errorf("ERROR : %s", err)
	}
}
コード例 #4
0
ファイル: example1.go プロジェクト: nitsnwits/go
// main is the entry point for the application.
func main() {
	// Retrieve a document for station 42002.
	stationID := "42002"
	station, err := buoy.FindStation(stationID)
	if err != nil {
		log.Printf("main : ERROR : %s\n", err)
		os.Exit(1)
	}

	buoy.Print(station)

	// Retrieve a slice of documents for the
	// Gulf Of Mexico region.
	region := "Gulf Of Mexico"
	stations, err := buoy.FindRegion(region, 5)
	if err != nil {
		log.Printf("main : ERROR : %s\n", err)
		os.Exit(1)
	}

	for _, station := range stations {
		buoy.Print(&station)
	}
}
コード例 #5
0
ファイル: example1_bench_test.go プロジェクト: nitsnwits/go
// BenchmarkStation provides stats for how this code is performing.
func BenchmarkStation(b *testing.B) {
	// Perform call to find a station.
	for i := 0; i < b.N; i++ {
		buoy.FindStation("42002")
	}
}