Esempio n. 1
0
// ExampleFlightGetMissingStartID tests giving a non existing startID value, with null output
func ExampleFlightGetMissingStartID() {
	plugin.Register("mockflight", &mock.Mock{})
	config.Set(config.Config{Global: config.Global{Flighter: "mockflight"}})
	_ = flag.Set("startID", "9")
	runFlightGet(CmdFlightGet, []string{})
	// Output:
}
Esempio n. 2
0
// ExampleFlightGetByID uses the mock flight implementation to query data and
// verify flight-get works. First, a specific id is passed. Second, a start id
// is passed.
func ExampleFlightGetByID() {
	plugin.Register("mockflightgetbyid", &mock.Mock{
		GetFlightByIDF: func(id int) (flight.Flight, error) {
			f := flight.Flight{
				Header: flight.Header{
					Date:       time.Date(2015, 1, 10, 0, 0, 0, 0, time.UTC),
					Pilot:      "MOCK PILOT 1",
					GliderType: "MOCK GLIDER 1", GliderID: "MOCK ID 1",
				},
				Sources: map[string]flight.Source{
					"netcoupe": flight.Source{
						Name:     "MOCK NAME 1",
						Category: "MOCK CATEGORY 1",
						Club:     "MOCK CLUB 1",
						Region:   "MOCK REGION 1",
						Country:  "MOCK COUNTRY 1",
						Distance: 100.01, Points: 100.02,
					},
				},
			}
			return f, nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Flighter: "mockflightgetbyid"}})
	_ = flag.Set("id", "1")
	_ = flag.Set("startID", "")
	_ = flag.Set("max", "")
	runFlightGet(CmdFlightGet, []string{})
	// Output:
	// 10/01/2015,MOCK PILOT 1,MOCK GLIDER 1,MOCK ID 1
	//	netcoupe,MOCK NAME 1,MOCK CATEGORY 1,MOCK CLUB 1,MOCK COUNTRY 1,MOCK REGION 1,100.01,100.02
}
Esempio n. 3
0
// ExampleFlightGetFromID queries using flight-get. First no max is given, so all records
// starting at 'startID' are returned. Second, a max is given so the number of results is limited.
func ExampleFlightGetFromID() {
	plugin.Register("mockflightgetfromid", &mock.Mock{
		GetFlightFromIDF: func(startID int, max int) ([]flight.Flight, error) {
			flights := []flight.Flight{
				flight.Flight{
					Header: flight.Header{
						Date:       time.Date(2015, 1, 10, 0, 0, 0, 0, time.UTC),
						Pilot:      "MOCK PILOT 1",
						GliderType: "MOCK GLIDER 1", GliderID: "MOCK ID 1",
					},
					Sources: map[string]flight.Source{
						"netcoupe": flight.Source{
							Name:     "MOCK NAME 1",
							Category: "MOCK CATEGORY 1",
							Club:     "MOCK CLUB 1",
							Region:   "MOCK REGION 1",
							Country:  "MOCK COUNTRY 1",
							Distance: 101.01, Points: 101.02,
						},
					},
				},
				flight.Flight{
					Header: flight.Header{
						Date:       time.Date(2015, 1, 11, 0, 0, 0, 0, time.UTC),
						Pilot:      "MOCK PILOT 2",
						GliderType: "MOCK GLIDER 2", GliderID: "MOCK ID 2",
					},
					Sources: map[string]flight.Source{
						"netcoupe": flight.Source{
							Name:     "MOCK NAME 2",
							Category: "MOCK CATEGORY 2",
							Club:     "MOCK CLUB 2",
							Region:   "MOCK REGION 2",
							Country:  "MOCK COUNTRY 2",
							Distance: 102.01, Points: 102.02,
						},
					},
				},
			}
			if max > 0 {
				flights = flights[0:max]
			}
			return flights, nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Flighter: "mockflightgetfromid"}})
	_ = flag.Set("startID", "1")
	_ = flag.Set("max", "")
	runFlightGet(CmdFlightGet, []string{})
	_ = flag.Set("max", "1")
	runFlightGet(CmdFlightGet, []string{})
	// Output:
	// 10/01/2015,MOCK PILOT 1,MOCK GLIDER 1,MOCK ID 1
	//	netcoupe,MOCK NAME 1,MOCK CATEGORY 1,MOCK CLUB 1,MOCK COUNTRY 1,MOCK REGION 1,101.01,101.02
	// 11/01/2015,MOCK PILOT 2,MOCK GLIDER 2,MOCK ID 2
	//	netcoupe,MOCK NAME 2,MOCK CATEGORY 2,MOCK CLUB 2,MOCK COUNTRY 2,MOCK REGION 2,102.01,102.02
	// 10/01/2015,MOCK PILOT 1,MOCK GLIDER 1,MOCK ID 1
	//	netcoupe,MOCK NAME 1,MOCK CATEGORY 1,MOCK CLUB 1,MOCK COUNTRY 1,MOCK REGION 1,101.01,101.02
}
Esempio n. 4
0
func TestWaypointPutBadGet(t *testing.T) {
	plugin.Register("mockwaypointbadget", mock.Mock{
		GetWaypointF: func(regions []string, updatedSince time.Time) ([]waypoint.Waypoint, error) {
			return nil, errors.New("mock testing get waypoint failed")
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Waypointer: "mockwaypointbadget"}})
	runWaypointPut(CmdWaypointPut, []string{"mockwaypointbadget"})
}
Esempio n. 5
0
func TestAirspaceGetFailed(t *testing.T) {
	plugin.Register("mockairspacegetfailed", &mock.Mock{
		GetAirspaceF: func(regions []string, updatedSince time.Time) ([]airspace.Airspace, error) {
			return nil, errors.New("mock testing get airspace failed")
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Airspacer: "mockairspacegetfailed"}})
	runAirspaceGet(CmdAirspaceGet, []string{})
}
Esempio n. 6
0
func TestFlightGetFromIDFailed(t *testing.T) {
	plugin.Register("mockflightgetfromidfailed", &mock.Mock{
		GetFlightFromIDF: func(startID int, max int) ([]flight.Flight, error) {
			return []flight.Flight{}, errors.New("mock testing get flight from id failed")
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Flighter: "mockflightgetfromidfailed"}})
	flag.Set("startID", "1")
	runFlightGet(CmdFlightGet, []string{})
}
Esempio n. 7
0
func TestWaypointGetBadAfter(t *testing.T) {
	plugin.Register("mockwaypointbadafter", &mock.Mock{
		GetWaypointF: func(regions []string, updatedSince time.Time) ([]waypoint.Waypoint, error) {
			return nil, nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Waypointer: "mockwaypointbadafter"}})
	flag.Set("after", "22-00-11")
	flag.Set("region", "")
	runWaypointGet(CmdWaypointGet, []string{})
}
Esempio n. 8
0
func TestAirfieldGetBadAfter(t *testing.T) {
	plugin.Register("mockairfieldbadafter", &mock.Mock{
		GetAirfieldF: func(regions []string, updatedSince time.Time) ([]airfield.Airfield, error) {
			return nil, nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Airfielder: "mockairfieldbadafter"}})
	flag.Set("after", "22-00-11")
	flag.Set("region", "")
	runAirfieldGet(CmdAirfieldGet, []string{})
}
Esempio n. 9
0
func TestWaypointGetFailed(t *testing.T) {
	plugin.Register("mockwaypointgetfailed", &mock.Mock{
		GetWaypointF: func(regions []string, updatedSince time.Time) ([]waypoint.Waypoint, error) {
			return nil, errors.New("mock testing get waypoint failed")
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Waypointer: "mockwaypointgetfailed"}})
	flag.Set("region", "")
	flag.Set("after", "")
	runWaypointGet(CmdWaypointGet, []string{})
}
Esempio n. 10
0
func TestAirfieldPutBadGet(t *testing.T) {
	plugin.Register("mockairfieldput", &mock.Mock{})
	plugin.Register("mockairfieldputbadget", &mock.Mock{
		GetAirfieldF: func(regions []string, updatedSince time.Time) ([]airfield.Airfield, error) {
			return nil, errors.New("mock testing get airfield failed")
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Airfielder: "mockairfieldputbadget"}})
	runAirfieldPut(CmdAirfieldPut, []string{"mockairfieldput"})
	// Output:
	// failed to get airfield :: mock testing get airfield failed
}
Esempio n. 11
0
func TestFlightGetFailed(t *testing.T) {
	plugin.Register("mockflightgetfailed", &mock.Mock{
		GetFlightByIDF: func(id int) (flight.Flight, error) {
			return flight.Flight{}, errors.New("mock testing get flight failed")
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Flighter: "mockflightgetfailed"}})
	flag.Set("id", "")
	flag.Set("startID", "")
	flag.Set("max", "")
	runFlightGet(CmdFlightGet, []string{})
}
Esempio n. 12
0
// ExampleAirspaceGet uses the mock airspace implementation to query data and
// verify airspace-get works. First, no region is passed. Second, a region but
// no updatedAfter is passed. Finally, both region and updatedAfter are given.
func ExampleAirspaceGet() {
	plugin.Register("mockairspaceget", &mock.Mock{
		GetAirspaceF: func(regions []string, updatedSince time.Time) ([]airspace.Airspace, error) {
			return []airspace.Airspace{
				airspace.Airspace{ID: "MockID", Date: time.Time{}, Class: 'C', Name: "MockName",
					Ceiling: "1000FT AMSL", Floor: "500FT AMSL", Update: time.Time{}},
			}, nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Airspacer: "mockairspaceget"}})
	runAirspaceGet(CmdAirspaceGet, []string{})
	// Output: {ID:MockID Date:0001-01-01 00:00:00 +0000 UTC Class:67 Name:MockName Ceiling:1000FT AMSL Floor:500FT AMSL Label:[] Segments:[] Pen:{Style:0 Width:0 Color:<nil> InsideColor:<nil>} Update:0001-01-01 00:00:00 +0000 UTC}
}
Esempio n. 13
0
func TestAirfieldGetFailed(t *testing.T) {
	plugin.Register("mockairfieldgetfailed", &mock.Mock{
		GetAirfieldF: func(regions []string, updatedSince time.Time) ([]airfield.Airfield, error) {
			return nil, errors.New("mock testing get airfield failed")
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Airfielder: "mockairfieldgetfailed"}})
	flag.Set("after", "")
	flag.Set("region", "")
	runAirfieldGet(CmdAirfieldGet, []string{})
	// Output:
	// failed to get airfield :: mock testing get airfield failed
}
Esempio n. 14
0
// ExampleFlightGetMissingID tests giving a non existing ID value, with null output
func ExampleFlightGetMissingID() {
	plugin.Register("mockflightmissingid", &mock.Mock{
		GetFlightByIDF: func(id int) (flight.Flight, error) {
			return flight.Flight{}, errors.New("given id does not exist")
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Flighter: "mockflightmissingid"}})
	_ = flag.Set("id", "9")
	_ = flag.Set("startID", "")
	_ = flag.Set("max", "")
	runFlightGet(CmdFlightGet, []string{})
	// Output:
}
Esempio n. 15
0
func TestWaypointPutFailed(t *testing.T) {
	plugin.Register("mockwaypointbadput", mock.Mock{
		PutWaypointF: func(waypoints []waypoint.Waypoint) error {
			return errors.New("mock testing put waypoint failed")
		},
	})
	plugin.Register("mockwaypoint", mock.Mock{
		GetWaypointF: func(regions []string, updatedSince time.Time) ([]waypoint.Waypoint, error) {
			return []waypoint.Waypoint{waypoint.Waypoint{}}, nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Waypointer: "mockwaypoint"}})
	runWaypointPut(CmdWaypointPut, []string{"mockwaypointbadput"})
}
Esempio n. 16
0
// ExampleAirfieldGet uses the mock airfield implementation to query data and
// verify airfield-get works. First, no region is passed. Second, a region but
// no updatedAfter is passed. Finally, both region and updatedAfter are given.
func ExampleAirfieldGet() {
	plugin.Register("mockairfieldget", &mock.Mock{
		GetAirfieldF: func(regions []string, updatedSince time.Time) ([]airfield.Airfield, error) {
			airfields := []airfield.Airfield{
				airfield.Airfield{
					ID: "MockID1", ShortName: "MockShortName",
					Name: "MockName", Region: "FR", ICAO: "AAAA", Flags: 0,
					Catalog: 11, Length: 1000, Elevation: 2000, Runway: "32R",
					Frequency: 123.45, Latitude: 32.533, Longitude: 100.376,
					Update: time.Date(2014, 02, 02, 0, 0, 0, 0, time.UTC)},
				airfield.Airfield{
					ID: "MockID2", ShortName: "MockShortName",
					Name: "MockName", Region: "CH", ICAO: "AAAA", Flags: 0,
					Catalog: 11, Length: 1000, Elevation: 2000, Runway: "32R",
					Frequency: 123.45, Latitude: 32.533, Longitude: 100.376,
					Update: time.Date(2014, 02, 02, 0, 0, 0, 0, time.UTC)},
				airfield.Airfield{
					ID: "MockID3", ShortName: "MockShortName",
					Name: "MockName", Region: "CH", ICAO: "AAAA", Flags: 0,
					Catalog: 11, Length: 1000, Elevation: 2000, Runway: "32R",
					Frequency: 123.45, Latitude: 32.533, Longitude: 100.376,
					Update: time.Date(2014, 02, 03, 0, 0, 0, 0, time.UTC)},
			}
			result := []airfield.Airfield{}
			for _, airfield := range airfields {
				b := false
				for _, r := range regions {
					if airfield.Region == r {
						b = true
					}
				}
				if airfield.Update.After(updatedSince) && b {
					result = append(result, airfield)
				}
			}
			return result, nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Airfielder: "mockairfieldget"}})
	_ = flag.Set("after", "2014-02-02")
	_ = flag.Set("region", "CH")
	runAirfieldGet(CmdAirfieldGet, []string{})
	// Output:
	// ID,ShortName,Name,Region,ICAO,Flags,Catalog,Length,Elevation,Runway,Frequency,Latitude,Longitude,Update
	// MockID3,MockShortName,MockName,CH,AAAA,0,11,1000,2000,32R,123.45,32.533,100.376,2014-02-03 00:00:00 +0000 UTC
}
Esempio n. 17
0
// ExampleWaypointGet uses the mock waypoint implementation to query data and
// verify waypoint-get works. First, no region is passed. Second, a region but
// no updatedAfter is passed. Finally, both region and updatedAfter are given.
func ExampleWaypointGet() {
	plugin.Register("mockwaypointget", &mock.Mock{
		GetWaypointF: func(regions []string, updatedSince time.Time) ([]waypoint.Waypoint, error) {
			waypoints := []waypoint.Waypoint{
				waypoint.Waypoint{
					ID: "MockID1", Name: "MockName",
					Description: "MockDescription", Region: "FR", Flags: 0,
					Elevation: 2000, Latitude: 32.533, Longitude: 100.376,
					Update: time.Date(2014, 02, 01, 0, 0, 0, 0, time.UTC),
				},
				waypoint.Waypoint{
					ID: "MockID2", Name: "MockName",
					Description: "MockDescription", Region: "CH", Flags: 0,
					Elevation: 2000, Latitude: 32.533, Longitude: 100.376,
					Update: time.Date(2014, 02, 02, 0, 0, 0, 0, time.UTC),
				},
				waypoint.Waypoint{
					ID: "MockID3", Name: "MockName",
					Description: "MockDescription", Region: "CH", Flags: 0,
					Elevation: 2000, Latitude: 32.533, Longitude: 100.376,
					Update: time.Date(2014, 02, 03, 0, 0, 0, 0, time.UTC),
				},
			}
			result := []waypoint.Waypoint{}
			for _, waypoint := range waypoints {
				b := false
				for _, r := range regions {
					if waypoint.Region == r {
						b = true
					}
				}
				if waypoint.Update.After(updatedSince) && b {
					result = append(result, waypoint)
				}
			}
			return result, nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Waypointer: "mockwaypointget"}})
	flag.Set("region", "CH")
	flag.Set("after", "2014-02-02")
	runWaypointGet(CmdWaypointGet, []string{})
	// Output:
	// ID,Name,Description,Region,Flags,Elevation,Latitude,Longitude,Update
	// MockID3,MockName,MockDescription,CH,0,2000,32.533,100.376,2014-02-03 00:00:00 +0000 UTC
}
Esempio n. 18
0
// ExampleWeb .
func ExampleWeb() {
	cfg := config.Config{}
	cfg.Web.Port = 7777
	plugin.Register("airfielder", mock.Mock{
		GetAirfieldF: func(regions []string, updatedSince time.Time) ([]airfield.Airfield, error) {
			return []airfield.Airfield{
				airfield.Airfield{ID: "MockID", ShortName: "MockShortName", Name: "MockName",
					Region: "FR", ICAO: "AAAA", Flags: 0, Catalog: 11, Length: 1000, Elevation: 2000,
					Runway: "32R", Frequency: 123.45, Latitude: 32.533, Longitude: 100.376},
			}, nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Airspacer: "airfielder"}})
	go runWeb(CmdWeb, []string{})
	// Output:
}
Esempio n. 19
0
func TestAirfieldPutFailed(t *testing.T) {
	plugin.Register("mockairfieldget", &mock.Mock{
		GetAirfieldF: func(regions []string, updatedSince time.Time) ([]airfield.Airfield, error) {
			return []airfield.Airfield{
				airfield.Airfield{ID: "MockID", ShortName: "MockShortName", Name: "MockName",
					Region: "FR", ICAO: "AAAA", Flags: 0, Catalog: 11, Length: 1000, Elevation: 2000,
					Runway: "32R", Frequency: 123.45, Latitude: 32.533, Longitude: 100.376,
					Update: time.Time{}},
			}, nil
		},
	})
	plugin.Register("mockairfieldputfailed", &mock.Mock{
		PutAirfieldF: func(airfields []airfield.Airfield) error {
			return errors.New("mock testing put airfield failed")
		},
	})
	config.Set(config.Config{Global: config.Global{Airfielder: "mockairfieldget"}})
	runAirfieldPut(CmdAirfieldPut, []string{"mockairfieldputfailed"})
	// Output:
	// failed to put airfield :: mock testing put airfield failed
}
Esempio n. 20
0
// ExampleWaypointPut uses the mock waypoint implementation to push data and
// verify waypoint-put works.
func ExampleWaypointPut() {
	plugin.Register("mockwaypoint", &mock.Mock{
		GetWaypointF: func(regions []string, updatedSince time.Time) ([]waypoint.Waypoint, error) {
			return []waypoint.Waypoint{
				waypoint.Waypoint{ID: "MockID", Name: "MockName", Description: "MockDescription",
					Region: "FR", Flags: 0, Elevation: 2000, Latitude: 32.533, Longitude: 100.576},
			}, nil
		},
	},
	)
	plugin.Register("mockwaypointput", &mock.Mock{
		PutWaypointF: func(waypoints []waypoint.Waypoint) error {
			return nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Waypointer: "mockwaypoint"}})
	runWaypointPut(CmdWaypointPut, []string{"mockwaypointput"})
	// Output:
	// pushed 1 waypoints into mockwaypointput
}
Esempio n. 21
0
// ExampleAirfieldPut uses the mock airfield implementation to push data and
// verify airfield-put works.
func ExampleAirfieldPut() {
	plugin.Register("mockairfield", &mock.Mock{
		GetAirfieldF: func(regions []string, updatedSince time.Time) ([]airfield.Airfield, error) {
			return []airfield.Airfield{
				airfield.Airfield{ID: "MockID", ShortName: "MockShortName", Name: "MockName",
					Region: "FR", ICAO: "AAAA", Flags: 0, Catalog: 11, Length: 1000, Elevation: 2000,
					Runway: "32R", Frequency: 123.45, Latitude: 32.533, Longitude: 100.376,
					Update: time.Time{}},
			}, nil
		},
	},
	)
	plugin.Register("mockairfieldput", &mock.Mock{
		PutAirfieldF: func(airfields []airfield.Airfield) error {
			return nil
		},
	},
	)
	config.Set(config.Config{Global: config.Global{Airfielder: "mockairfield"}})
	runAirfieldPut(CmdAirfieldPut, []string{"mockairfieldput"})
	// Output:
	// pushed 1 airfields into mockairfieldput
}
Esempio n. 22
0
func TestAirspaceGetBadPluginID(t *testing.T) {
	config.Set(config.Config{Global: config.Global{Airspacer: "mockairspacenonexisting"}})
	runAirspaceGet(CmdAirspaceGet, []string{})
}