Exemplo n.º 1
0
func TestSettingsLoad(t *testing.T) {
	assert := assert.New(t)

	err := models.LoadLobbySettings(testSettingsData)

	if assert.Nil(err) {
		// test formats
		if assert.Equal(3, len(models.LobbyFormats)) {
			if format, ok := models.GetLobbyFormat("sixes"); assert.True(ok) {
				assert.Equal("6v6", format.PrettyName)
				assert.Equal(true, format.Important)
			}

			if format, ok := models.GetLobbyFormat("highlander"); assert.True(ok) {
				assert.Equal("Highlander", format.PrettyName)
				assert.Equal(true, format.Important)
			}

			if format, ok := models.GetLobbyFormat("fours"); assert.True(ok) {
				assert.Equal("4v4", format.PrettyName)
				assert.Equal(false, format.Important)
			}
		}

		// test maps
		if assert.Equal(2, len(models.LobbyMaps)) {
			if amap, ok := models.GetLobbyMap("cp_process_final"); assert.True(ok) {
				assert.Equal(2, len(amap.Formats))

				if mapFormat, ok := amap.GetFormat("highlander"); assert.True(ok) {
					assert.Equal(1, mapFormat.Importance)
				}
				if mapFormat, ok := amap.GetFormat("sixes"); assert.True(ok) {
					assert.Equal(2, mapFormat.Importance)
				}
				if mapFormat, ok := amap.GetFormat("fours"); assert.True(ok) {
					assert.Equal(0, mapFormat.Importance)
				}
			}

			if amap, ok := models.GetLobbyMap("pl_upward"); assert.True(ok) {
				assert.Equal(1, len(amap.Formats))

				if mapFormat, ok := amap.GetFormat("highlander"); assert.True(ok) {
					assert.Equal(2, mapFormat.Importance)
				}
			}
		}

		// TODO write more tests, pls

		output, err := models.LobbySettingsToJson().Encode()
		if assert.Nil(err) {
			fmt.Println(string(output))
		}
	}
}
Exemplo n.º 2
0
func (Global) GetConstant(server *wsevent.Server, so *wsevent.Client, data []byte) []byte {
	var args struct {
		Constant string `json:"constant"`
	}
	if err := chelpers.GetParams(data, &args); err != nil {
		return helpers.NewTPErrorFromError(err).Encode()
	}

	output := simplejson.New()
	switch args.Constant {
	case "lobbySettingsList":
		output = models.LobbySettingsToJson()
	default:
		return helpers.NewTPError("Unknown constant.", -1).Encode()
	}

	bytes, _ := chelpers.BuildSuccessJSON(output).Encode()
	return bytes
}